<%@ page import="java.util.*" contentType="text/html"%>
<%@ page import="model.Measurement" contentType="text/html"%>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
    	
		<script type="text/javascript">
		  	google.load('visualization', '1', {packages: ['corechart']});
		</script>
		<script type="text/javascript">
				
        function drawVisualization() {
           var data = new google.visualization.DataTable();
           data.addColumn('string', 'Year');
           data.addColumn('number', 'Licht sterkte');          
           
           <% 
           int dagen = 1;
           if(request.getAttribute("dagenVerschil") == null){
           } else{
           	  dagen = (Integer)request.getAttribute("dagenVerschil");
           }
           	  int[] urenWaardes = (int[])request.getAttribute("dagenLijst");
         	  if(dagen != -1 && request.getAttribute("dagenLijst") != null && request.getAttribute("lichtSterkte") != null && urenWaardes[0] != 0){
   		  			int[][] waardes = (int[][])request.getAttribute("lichtSterkte");
   		  		    dagen = (Integer)request.getAttribute("dagenVerschil");
   		  		    
   		  		    for(int x = 0; x < dagen; x++){
       	 	 			for(int i = 0; i<urenWaardes.length; i++){	%>
       						var date = '<%= urenWaardes[i] %>';
       	 					var getal = <%= waardes[x][i]%>;
       						data.addRows([[ date , getal]]  );
       	 	 	<%  }   } 
   		  		    
	 	  }else if(request.getAttribute("dagenLijst") == null &&  !request.getAttribute("eersteKeer").equals("eersteKeer") && (Integer)request.getAttribute("keerGedaan") <1 ){
	 		  request.setAttribute("keerGedaan", (Integer)request.getAttribute("keerGedaan") +1 ); %>
	 		 alert("kan niet meer dan 28 dagen verschil zijn"); <%
	 	  } else if( !request.getAttribute("eersteKeer").equals("eersteKeer") && (Integer)request.getAttribute("keerGedaan") <1 ){
	     	 	  request.setAttribute("keerGedaan", (Integer)request.getAttribute("keerGedaan") +1 ); %>
			alert("geen geldige invoer");
     	   <% } %>
       	  
          // Create and draw the visualization.
       	var ac = new google.visualization.AreaChart(document.getElementById('lichtSterkte'));
         ac.draw(data, {
           isStacked: true,
           width: 600,
           height: 400, 
           vAxis: {title: 'licht sterkte', minValue: 0, maxValue: 35000},
           hAxis: {title: "Uren"}
         });
       	}
         google.setOnLoadCallback(drawVisualization);
      </script>